﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ExBug
{
    public partial class PACRezFrm : FrmRezumat
    {

        private BindingSource bs = null;
        private BindingSource bsDetaliu = null;


        public PACRezFrm(BindingSource _bs, BindingSource _bsDetaliu, ModuleClass mc)
            : base(mc)
        {
            if (_bs != null && _bsDetaliu!=null )
            {
                InitializeBindingSource(_bs, _bsDetaliu);
                bs = _bs;
                bsDetaliu = _bsDetaliu;
            }

            InitializeComponent();
        }

        private void ALRezFrm_Load(object sender, EventArgs e)
        {
            
            if (ModuleInfo.CurrentTheme == "tribunal")
            {
                AddButton("Adauga[F8]", global::ERPStudio.Properties.Resources.adauga, AdaugaAL, ToolStripItemAlignment.Left, false);
                HandleDel += Adauga;
            }

            SqlConnection con = DeschideConexiune(workConnString);
            jurnaleTableAdapter.Connection = con;
            jurnaleTableAdapter.Fill(eSRPDataSet.Jurnale, ModuleInfo.CodUnitate);
            
            persoaneVizaCFPTableAdapter.Connection = con;
            persoaneVizaCFPTableAdapter.Fill(eSRPDataSet.PersoaneVizaCFP, ModuleInfo.CodUnitate);
            //this.angajamentLegalDetaliuTableAdapter.Connection = con;
            if (listBndSourceMain.Count == 0)
            {
                propunereAngajareCheltuialaDetaliuTableAdapter.Connection = con;
                propunereAngajareCheltuialaDetaliuTableAdapter.Fill(eSRPDataSet.PropunereAngajareCheltuialaDetaliu);
                //this.angajamentLegalDetaliuTableAdapter.Fill(this.eSRPDataSet.AngajamentLegalDetaliu);
                //this.angajamentLegalTableAdapter.Connection = con;
                propunereAngajareCheltuialaTableAdapter.Connection = con;
                propunereAngajareCheltuialaTableAdapter.Fill(eSRPDataSet.PropunereAngajareCheltuiala, ModuleInfo.CodUnitate);
            }
            //this.angajamentLegalTableAdapter.Fill(this.eSRPDataSet.AngajamentLegal, ModuleInfo.CodUnitate);
            InchideConexiune(con);

            if (listBndSourceMain.Count > 0)
            {
                PACDGV.DataSource = listBndSourceMain[0];
                PACDetaliuDGV.DataSource = listBndSourceMain[1];
            }
        }

        private void AdaugaAL(object sender, EventArgs e)
        {
            PACFrm frm = new PACFrm(ModuleInfo);
            //frm.MdiParent = MdiParent;
            //frm.AddMode = true;
            frm.ShowDialog();
            if (frm.NoRecUpdated != 0)
            {
                SqlConnection con = DeschideConexiune(workConnString);
                propunereAngajareCheltuialaDetaliuTableAdapter.Connection = con;
                propunereAngajareCheltuialaDetaliuTableAdapter.Fill(eSRPDataSet.PropunereAngajareCheltuialaDetaliu);
                propunereAngajareCheltuialaTableAdapter.Connection = con;
                propunereAngajareCheltuialaTableAdapter.Fill(eSRPDataSet.PropunereAngajareCheltuiala, ModuleInfo.CodUnitate);

                /*this.angajamentLegalDetaliuTableAdapter.Connection = con;
                this.angajamentLegalDetaliuTableAdapter.Fill(this.eSRPDataSet.AngajamentLegalDetaliu);
                this.angajamentLegalTableAdapter.Connection = con;
                this.angajamentLegalTableAdapter.Fill(this.eSRPDataSet.AngajamentLegal, ModuleInfo.CodUnitate);*/
                InchideConexiune(con);
            }
        }

        
    }
}
